//处理字典对象
zUtil.dictConvertHandler = function(value,type,dictData){
    var oldValue = value;
    if(value && 'undefined' !== $.type(type) && type){
        if('string' === $.type(type) || 'object' === $.type(type)){//字典取或者key-value形式
            var dicts = ('object' === $.type(type)?type:dictData[type]);
            var getDesc = function(value){
                var nlabel = dicts[value];
                if('object' === $.type(nlabel)){
                  if(nlabel["labelCode"]){
                      nlabel = nlabel["labelCode"];
                  }else if(nlabel["text"]){
                      nlabel = nlabel["text"];
                  }
                }
                return nlabel;
            };
            if('undefined' !== $.type(dicts) && 'undefined' !== $.type(dicts[value]) && dicts[value] !== null){
                value = getDesc(value);
            }else if('string' === $.type(value) && value.indexOf(",") != -1){
                var arrval = value.split(",");
                var desc = [];
                $.each(arrval,function(i, val){
                    var nlabel = getDesc(val);
                    if(nlabel){
                       desc.push(nlabel);
                    }else{
                       desc.push(val);
                    }
                });
                if(desc.length>0){
                    value = desc.join(","); 
                }
            }
        }
      }
      if(!value){
          value = oldValue;
      }
      return value;
}

/** zDict字典按TYPE转换CODE*/
zUtil.dictConvertOfSys = function(value,type){
    return zUtil.dictConvertHandler(value, type, zDictSys);
};
/** zAutocodeDict字典按TYPE转换CODE*/
zUtil.dictConvertOfAutocode = function(value,type){
    return zUtil.dictConvertHandler(value, type, zDictAutocode);
}

/**字典装配字典-同步,type:逗号分割*/
zUtil.dictLoadSyncOfSys = function(type,keyValue){
    if('undefined' === $.type(keyValue)){
      keyValue = null;
    }
    var selectArr = type.split(",");
    var type1 = [];
    var type2 = [];
    $.each(selectArr,function(i,item){
        if(item.indexOf("ZSELECT_") > -1){
            type2.push(item);
        }else{
            type1.push(item);
        }
    });
    if(type1.length > 0){
        var result = zUtil.ajaxGetSync(zApi["sysDictCode"],{type: type1.join(","), key:keyValue});
        if(zCode["GLOBAL_SUCCESS"] === zUtil.getVal(result,zConst["busCode"]) && result[zConst["resData"]] !== null){
            zDictSys = $.extend(true,zDictSys,result[zConst["resData"]]);
        }
    }
    if(type2.length > 0){
        var result = zUtil.ajaxGetSync(zApi["sysSelectCode"],{type: type2.join(","), key:keyValue});
        if(zCode["GLOBAL_SUCCESS"] === zUtil.getVal(result,zConst["busCode"]) && result[zConst["resData"]] !== null){
            zDictSys = $.extend(true,zDictSys,result[zConst["resData"]]);
        }
    }
};
/**字典装配字典-同步,type:逗号分割*/
zUtil.dictLoadSyncOfAutocode = function(type,keyValue){
    if('undefined' === $.type(keyValue)){
      keyValue = null;
    }
    var selectArr = type.split(",");
    var type1 = [];
    var type2 = [];
    $.each(selectArr,function(i,item){
        if(item.indexOf("ZSELECT_") > -1){
            type2.push(item);
        }else{
            type1.push(item);
        }
    });
    if(type1.length > 0){
        var result = zUtil.ajaxGetSync(zApi["autocodeDictCode"],{type: type1.join(","), key:keyValue});
        if(zCode["GLOBAL_SUCCESS"] === zUtil.getVal(result,zConst["busCode"]) && result[zConst["resData"]] !== null){
            zDictAutocode = $.extend(true,zDictAutocode,result[zConst["resData"]]);
        }
    }
    if(type2.length > 0){
        var result = zUtil.ajaxGetSync(zApi["autocodeSelectCode"],{type: type2.join(","), key:keyValue});
        if(zCode["GLOBAL_SUCCESS"] === zUtil.getVal(result,zConst["busCode"]) && result[zConst["resData"]] !== null){
            zDictAutocode = $.extend(true,zDictAutocode,result[zConst["resData"]]);
        }
    }
};